package com.zhuoyue.servlet;

import com.alibaba.fastjson.JSON;
import com.zhuoyue.po.FileElement;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ShowFilesServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        File f = new File("/server");
        File[] fs = f.listFiles();
        List<FileElement> list = new ArrayList<>();
        for (File f1:fs){
            FileElement fe = new FileElement(f1.getName(),f1.getPath().replace("\\","/"));
            list.add(fe);
        }
        String str = JSON.toJSONString(list);
        response.getWriter().println(str);
    }
}
